home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-08-31 | 2.1 KB | 58 lines | [TEXT/CCL ] |
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; Copyright 1987, 1988, 1989, 1990 by Ruben Kleiman for Apple Computer, Inc.
- ;;; Advanced Technology Group
- ;;;
-
- ;;;
- ;;; This file allows any function to be part of the eventhook
- ;;;
-
- (in-package :event :use '(lisp system ccl))
-
- (export '(add-eventhook remove-eventhook is-eventhook))
-
- (defvar *fast-eventhooks* ()
- "Holds forms to be evaluated at interrupt level")
-
- (defvar *delayed-eventhooks* ()
- "Holds forms to be frequently enqueued for evaluation at the lisp top level")
-
- ;;; Two types of forms may be hooked: (1) an eval-enqueue form (type :¨SLOW), or (2) a
- ;;; real-time hook (type :FAST). These get executed at the top-level or at event
- ;;; processing time, respectively. The latter kind of hook must be efficient.
- (defun add-eventhook (form &optional (type :fast))
- "To add a periodically executed background form"
- (without-interrupts
- (if (eql type :fast)
- (push form *fast-eventhooks*)
- (push form *delayed-eventhooks*))
- (unless *eventhook*
- (setq *eventhook* 'eventhook-monitor))))
-
- ;;; Should probably be without-interrupts, but the packages mess up in 1.2d10
- (defun remove-eventhook (form &optional (type :fast))
- "To remove a periodically executed background form"
- (without-interrupts
- (if (eql type :fast)
- (setq *fast-eventhooks* (delete form *fast-eventhooks* :test #'equal))
- (setq *delayed-eventhooks* (delete form *delayed-eventhooks* :test #'equal)))
- (unless (or *fast-eventhooks*
- *delayed-eventhooks*)
- (setq *eventhook* nil))))
-
- (defun is-eventhook (form)
- "Is this form being periodically executed in the background?"
- (without-interrupts
- (or (member form *fast-eventhooks* :test #'equal)
- (member form *delayed-eventhooks* :test #'equal))))
-
- (defun eventhook-monitor ()
- "Periodically evals certain forms in the background"
- (and *fast-eventhooks*
- (dolist (h *fast-eventhooks*)
- (eval h)))
- (and *delayed-eventhooks*
- (dolist (h *delayed-eventhooks*)
- (eval-enqueue h))))
-
- (provide :event)